
package com.audaque.springboot.foshanupload.web.casclientautoconfigsupportdemo1.service.impl;



import com.audaque.springboot.foshanupload.web.casclientautoconfigsupportdemo1.mapper.druid.OrderDetailDruidMapper;
import com.audaque.springboot.foshanupload.web.casclientautoconfigsupportdemo1.mapper.druid.OrderDruidMapper;
import com.audaque.springboot.foshanupload.web.casclientautoconfigsupportdemo1.model.Order;
import com.audaque.springboot.foshanupload.web.casclientautoconfigsupportdemo1.model.OrderDetail;
import com.audaque.springboot.foshanupload.web.casclientautoconfigsupportdemo1.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.UUID;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDruidMapper orderDruidMapper;

    @Autowired
    private OrderDetailDruidMapper detailMapper;

    @Transactional(propagation = Propagation.REQUIRED)
    public int insertOrder() {
        Order record = new Order();
        String orderno = UUID.randomUUID().toString();
        System.out.println("orderno:" + orderno);
        record.setOrderNo(orderno);
        record.setCreateDate(new Date());

        OrderDetail detail = new OrderDetail();
        detail.setOrderNo(orderno);
        detail.setProductName("牛肉干");
        detail.setCreateDate(new Date());

        orderDruidMapper.insert(record);
        this.insertOrderDetail(detail);
        //int a = 1 / 0;
//		try{
//
//
//		}catch(Exception e){
//			//TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//		}

        return 0;
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void insertOrderDetail(OrderDetail record) {
        detailMapper.insert(record);
    }
}
